home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-10-20 | 6.9 KB | 219 lines | [TEXT/GEOL] |
- Item 4929214 19-Oct-89 12:29
-
- From: D2086 Efficient Field Svc, C Faith,PRT
-
- To: APPLE.BUGS Apple Bugs Reporting
- MACAPP.TEST MacApp SQA Team
- MACAPP.TECH$ MACAPP Tech
-
- Sub: TDialogView Bug Fixes (long)
-
- This is an update on problems I have been having with TDialogView and the
- solution I have devised.
-
- There are 3 bugs involved:
-
- 1) a default Control does not Flash when return, enter, cancel or Esc is
- pressed unless the Control dismisses.
-
- 2) the application must be aware of which Controls are default and cancel (if
- the dialog has a DoChoice override) because the itsChoice is not the same as if
- the Control had been hit with a mouse it is mDefaultKey or mCancelKey.
- This means that changing just the resource file to reflect a different default
- key will often not work.
-
- 3) Using DeselectCurrentEditText as a method yourself in a TDialogView Override
- can cause TEditText.DoMouseCommand to bomb. This is because the method does
- not change gTarget and TEditText.DoMouseCommand assumes that it is already
- selected if gTarget is equal to SELF, (which is not the case after a call to
- DeselectCurrentEditText since it did not change gTarget).
-
- The solution I have devised to the first 2 problems is related. I tried to
- make the actions of TDialogView.DoKeyCommand treat the item just as if it had
- been pressed with a mouse, I passed fDefChoice instead of mDefaultKey etc. The
- only problem with this is that TDialogView.DoChoice flashes the dismisser when
- it gets a mDefaultKey but not when its gets the mButtonHit for example. This
- is because TrackControl has already flashed the button by the time it gets to
- DoChoice with a mButtonHit.
-
- Recall that bug 1 above also involves flashing default controls, so to fix the
- flashing I simply flash the control in TDialogView.DoKeyCommand whenever a
- default or cancel key is pressed. This means that there is no longer any reason
- to distinguish between mButtonHit and mDefaultKey as they will already have
- been flashed by the time they get to the DoChoice method, and DismissDialog
- will no longer need to flash. Hence I removed the flashDismisser parameter and
- code completely from DismissDialog.
-
- The third bug is perhaps a little less resolved. I am not sure exactly what
- the best solution is. I have changed DeselectCurrentEditText to change the
- target to the dialog or SELF for now and this works fine. Perhaps it should be
- set to something else ?.
-
- Hope Someone finds this useful,
-
- Curtis
-
- The changes I have made are as follows:
-
- {$S DlgClose}
- { +++ Changed the interface for DismissDialog removed flashDismisser reference
- }
- PROCEDURE TDialogView.DismissDialog(dismisser: IDType);
-
- BEGIN
- IF NOT fDismissed THEN
- IF CanDismiss(dismisser) THEN
- BEGIN
- fDismissed := TRUE;
- fDismisser := dismisser;
- END
- ELSE
- Failure(noErr, 0); { Silent failure }
- END;
-
- {------------------------------------------------------------------------------
- --------------------}
- PROCEDURE TDialogView.DoChoice(origView: TView; itsChoice: INTEGER); OVERRIDE;
-
- BEGIN
- CASE itsChoice OF
- mEditTextHit:
- BEGIN
- {$IFC qDebug}
- IF NOT Member(origView, TEditText) THEN
- ProgramBreak('Got mEditTextHit on non-TEditText view.')
- ELSE
- {$ENDC}
- DoSelectEditText(TEditText(origView), False);
- END;
-
- { +++ Removed special case for mDefaultKey, mCancelKey }
-
- OTHERWISE
- IF Member(origView, TControl) & TControl(origView).fDismissesDialog THEN
- DismissDialog(origView.fIdentifier)
- ELSE
- INHERITED DoChoice(origView, itsChoice);
- END;
- END;
-
- {------------------------------------------------------------------------------
- --------------------}
- {$S DlgRes}
-
- FUNCTION TDialogView.DoCommandKey(ch: CHAR; VAR info: EventInfo): TCommand;
- OVERRIDE;
- VAR
- cancelView: TView;
-
- BEGIN
- IF IsViewEnabled & (ch = '.') & (LONGINT(fCancelItem) <>
- LONGINT(kNoIdentifier)) THEN
- BEGIN { +++ Changed below to pass fDefChoice for Controls }
- cancelView := FindSubView(fCancelItem);
- IF (cancelView <> NIL) & Member(cancelView, TControl) THEN
- BEGIN
- TControl(cancelView).Flash;
- DoChoice(cancelView, TControl(cancelView).fDefChoice);
- END
- ELSE
- DoChoice(cancelView, mCancelKey);
- DoCommandKey := gNoChanges;
- END
- ELSE
- DoCommandKey := INHERITED DoCommandKey(ch, info);
- END;
-
- {------------------------------------------------------------------------------
- --------------------}
- {$S DlgRes}
-
- FUNCTION TDialogView.DoKeyCommand(ch: CHAR; aKeyCode: INTEGER;
- VAR info: EventInfo): TCommand; OVERRIDE;
- VAR
- defaultView:TView;
- cancelView: TView;
-
- BEGIN
- { If we get this far, nobody's handled the Tab, Enter, or Return keys, so we
- will }
- DoKeyCommand := gNoChanges;
- IF IsViewEnabled THEN
- CASE ch OF
- chEscape:
- IF aKeyCode = kClearVirtualCode THEN
- DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info)
- ELSE IF LONGINT(fCancelItem) <> LONGINT(kNoIdentifier) THEN
- BEGIN { +++ Changed below to pass fDefChoice for Controls }
- cancelView := FindSubView(fCancelItem);
- IF (cancelView <> NIL) & Member(cancelView, TControl) THEN
- BEGIN
- TControl(cancelView).Flash;
- DoChoice(cancelView, TControl(cancelView).fDefChoice);
- END
- ELSE
- DoChoice(cancelView, mCancelKey);
- END;
- chTab:
- Tab(info.theShiftKey);
- chEnter, chReturn:
- IF LONGINT(fDefaultItem) <> LONGINT(kNoIdentifier) THEN
- BEGIN { +++ Changed below to pass fDefChoice for Controls }
- defaultView := FindSubView(fDefaultItem);
- IF (defaultView <> NIL) & Member(defaultView, TControl) THEN
- BEGIN
- TControl(defaultView).Flash;
- DoChoice(defaultView, TControl(defaultView).fDefChoice);
- END
- ELSE
- DoChoice(defaultView, mDefaultKey);
- END;
- OTHERWISE
- DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
- END
- ELSE
- DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
- END;
-
- {------------------------------------------------------------------------------
- --------------------}
- FUNCTION TDialogView.DeselectCurrentEditText: BOOLEAN;
-
- VAR
- validateResult: LONGINT;
- itsWindow: TWindow;
-
- BEGIN
- DeselectCurrentEditText := TRUE;
-
- IF fCurrentEditText <> NIL THEN
- BEGIN
- { Commit the last command to prevent undo from applying to the wrong edit
- text,
- and to ensure that all changes are made before validating. }
- IF (gLastCommand <> NIL) & (gLastCommand.fView = fTEView) THEN
- gApplication.CommitLastCommand;
-
- validateResult := fCurrentEditText.Validate;
- IF validateResult = kValidValue THEN
- BEGIN
- fCurrentEditText.StopEdit;
- fCurrentEditText := NIL;{ No edit text is selected }
- { +++ Added this to change target }
- itsWindow := GetWindow; { Set the window's target to self }
- IF itsWindow <> NIL THEN
- itsWindow.SetTarget(SELF)
- ELSE
- gApplication.SetTarget(gApplication);
- END
- ELSE
- BEGIN
- CantDeselect(fCurrentEditText, validateResult);
- DeselectCurrentEditText := False;
- END;
- END;
- END;
-
-
-
-